package com.lagou.edu.Interceptor;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse
            response, Object handler) throws Exception {
        Object username = request.getSession().getAttribute("username");
        if (StringUtils.isEmpty(username)) {
            response.sendRedirect("/login");
            return false;
        }
        return true;
    }
}
